package day01;

import java.util.Stack;

/**
 * @author Jetwang
 * @version 1.0
 * @since 2023/3/11 21:38
 * 用两个栈实现队列
 */
public class Offer09 {
    // 存数据
    Stack<Integer> stack01 = new Stack<>();
    // 出数据
    Stack<Integer> stack02 = new Stack<>();

    public Offer09() {

    }

    public void appendTail(int value) {
        stack01.push(value);
    }

    public int deleteHead() {
        if (stack02.isEmpty() && stack01.isEmpty()) return -1;
        if (!stack02.isEmpty()) {
            return stack02.pop();
        } else {
            while(!stack01.isEmpty()) {
                stack02.push(stack01.pop());
            }
        }
        return stack02.pop();
    }
}
